/**
 * Copyright 2011 Marco Berri - marcoberri@gmail.com
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 *
 */
package com.mbfasttrack.model;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import javax.validation.constraints.NotNull;
import org.springframework.data.annotation.Id;
import org.springframework.data.annotation.Transient;
import org.springframework.data.mongodb.core.index.GeoSpatialIndexed;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;
import org.springframework.web.multipart.commons.CommonsMultipartFile;

/**
 * @author Marco Berri marcoberri@gmail.com http://tecnicume.blogspot.com
 */
@Document
public class User implements Base {

    @Id
    @Indexed(unique = true)
    private String id;
    @NotNull
    private String firstname;
    @NotNull
    private String lastname;
    @GeoSpatialIndexed
    private double[] locationPoint = {0.0, 0.0};
    private String location;
    @Transient
    private Double coordx;
    @Transient
    private Double coordy;
    //blocco di login
    @Indexed(unique = true)
    @NotNull
    private String username;
    @Indexed(unique = true)
    @NotNull
    private String email;
    //access
    @NotNull
    private String password;
    @NotNull
    private Boolean enable = Boolean.TRUE;
    @NotNull
    private Boolean accountNonExpired = Boolean.TRUE;
    @NotNull
    private Boolean credentialsNonExpired = Boolean.TRUE;
    @NotNull
    private Boolean accountNonLocked = Boolean.TRUE;
    @NotNull
    private String role = "ROLE_USER";
    @NotNull
    private Date lastLogin = new Date(System.currentTimeMillis());
    //Stats
    private Boolean confirmRegistration;
    private Double totElevation = 0.0;
    private Double totRealElevation = 0.0;
    private Double totDistance = 0.0;
    private Integer totTracks = 0;
    private long totTime;
    //privacy
    private Boolean locationPublic = Boolean.FALSE;
    private Boolean dashboardPublic = Boolean.FALSE;
    private Boolean emailPublic = Boolean.FALSE;
    private Boolean lastnamePublic = Boolean.FALSE;
    private Boolean firstnamePublic = Boolean.FALSE;
    //avatar
    @Transient
    private CommonsMultipartFile avatar;
    //tags
    @DBRef
    private List<Tag> tagsLink = new ArrayList();
    //media - tra cui l'avatar
    @DBRef
    private List<Media> media = new ArrayList();

    /**
     *
     * @return
     */
    @Override
    public String toString() {
        return "User [id=" + getId()
                + ", email=" + getEmail()
                + ", username=" + getUsername()
                + ", firstname=" + this.firstname
                + ", lastname=" + this.lastname
                + ", password=" + this.password
                + ", enable=" + this.enable
                + ", accountNonExpired=" + this.accountNonExpired
                + ", credentialsNonExpired=" + this.credentialsNonExpired
                + ", accountNonLocked=" + this.accountNonLocked
                + ", confirmRegistration=" + this.confirmRegistration
                + ", role=" + this.role
                + ", lastLogin=" + this.lastLogin
                + ", locationPoint=" + this.locationPoint
                + ", location=" + this.location
                + ", coordx=" + this.coordx
                + ", coordy=" + this.coordy
                + ", totRealElevation=" + this.totRealElevation
                + ", totRealElevation=" + this.totRealElevation
                + ", totTime=" + this.totTime
                + ", locationPublic=" + this.locationPublic
                + ", dashboardPublic=" + this.dashboardPublic
                + ", emailPublic=" + this.emailPublic
                + ", lastnamePublic=" + this.lastnamePublic
                + ", firstnamePublic=" + this.firstnamePublic
                + ", tagsLink=" + this.tagsLink
                + ", media=" + this.media
                + ", avatar=" + this.avatar
                + ", totDistance=" + this.totDistance
                + ", totTracks=" + this.getTotTracks()
                + "]";
    }

    /**
     *
     */
    public User() {
    }

    /**
     *
     * @return
     */
    public String getId() {
        return id;
    }

    /**
     *
     * @param id
     */
    public void setId(String id) {
        this.id = id;
    }

    /**
     * @return the firstname
     */
    public String getFirstname() {
        return firstname;
    }

    /**
     * @param firstname the firstname to set
     */
    public void setFirstname(String firstname) {
        this.firstname = firstname;
    }

    /**
     * @return the lastname
     */
    public String getLastname() {
        return lastname;
    }

    /**
     * @param lastname the lastname to set
     */
    public void setLastname(String lastname) {
        this.lastname = lastname;
    }

    /**
     * @return the email
     */
    public String getEmail() {
        return email;
    }

    /**
     * @param email the email to set
     */
    public void setEmail(String email) {
        this.email = email;
    }

    /**
     *
     * @param password
     */
    public void setPassword(String password) {
        this.password = password;
    }

    /**
     *
     * @param password
     * @return
     */
    public boolean checkPassword(String password) {
        return true;
    }

    /**
     * @return the confirmRegistration
     */
    public Boolean getConfirmRegistration() {
        return confirmRegistration;
    }

    /**
     * @param confirmRegistration the confirmRegistration to set
     */
    public void setConfirmRegistration(Boolean confirmRegistration) {
        this.confirmRegistration = confirmRegistration;
    }

    /**
     * @return the password
     */
    public String getPassword() {
        return password;
    }

    /**
     * @return the enable
     */
    public Boolean getEnable() {
        return enable;
    }

    /**
     * @param enable the enable to set
     */
    public void setEnable(Boolean enable) {
        this.enable = enable;
    }

    /**
     * @return the accountNonExpired
     */
    public Boolean getAccountNonExpired() {
        return accountNonExpired;
    }

    /**
     * @param accountNonExpired the accountNonExpired to set
     */
    public void setAccountNonExpired(Boolean accountNonExpired) {
        this.accountNonExpired = accountNonExpired;
    }

    /**
     * @return the credentialsNonExpired
     */
    public Boolean getCredentialsNonExpired() {
        return credentialsNonExpired;
    }

    /**
     * @param credentialsNonExpired the credentialsNonExpired to set
     */
    public void setCredentialsNonExpired(Boolean credentialsNonExpired) {
        this.credentialsNonExpired = credentialsNonExpired;
    }

    /**
     * @return the accountNonLocked
     */
    public Boolean getAccountNonLocked() {
        return accountNonLocked;
    }

    /**
     * @param accountNonLocked the accountNonLocked to set
     */
    public void setAccountNonLocked(Boolean accountNonLocked) {
        this.accountNonLocked = accountNonLocked;
    }

    /**
     * @return the role
     */
    public String getRole() {
        return role;
    }

    /**
     * @param role the role to set
     */
    public void setRole(String role) {
        this.role = role;
    }

    /**
     * @return the lastLogin
     */
    public Date getLastLogin() {
        return lastLogin;
    }

    /**
     * @param lastLogin the lastLogin to set
     */
    public void setLastLogin(Date lastLogin) {
        this.lastLogin = lastLogin;
    }

    /**
     * @return the username
     */
    public String getUsername() {
        return username;
    }

    /**
     * @param username the username to set
     */
    public void setUsername(String username) {
        this.username = username;
    }

    /**
     * @param location the location to set
     */
    public void setLocation(String location) {
        this.location = location;
    }

    /**
     * @return the firstnamePublic
     */
    public Boolean getFirstnamePublic() {
        return firstnamePublic;
    }

    /**
     * @param firstnamePublic the firstnamePublic to set
     */
    public void setFirstnamePublic(Boolean firstnamePublic) {
        this.firstnamePublic = firstnamePublic;
    }

    /**
     * @return the lastnamePublic
     */
    public Boolean getLastnamePublic() {
        return lastnamePublic;
    }

    /**
     * @param lastnamePublic the lastnamePublic to set
     */
    public void setLastnamePublic(Boolean lastnamePublic) {
        this.lastnamePublic = lastnamePublic;
    }

    /**
     * @return the locationPublic
     */
    public Boolean getLocationPublic() {
        return locationPublic;
    }

    /**
     * @param locationPublic the locationPublic to set
     */
    public void setLocationPublic(Boolean locationPublic) {
        this.locationPublic = locationPublic;
    }

    /**
     * @return the emailPublic
     */
    public Boolean getEmailPublic() {
        return emailPublic;
    }

    /**
     * @param emailPublic the emailPublic to set
     */
    public void setEmailPublic(Boolean emailPublic) {
        this.emailPublic = emailPublic;
    }

    /**
     * @return the location
     */
    public String getLocation() {
        return location;
    }

    /**
     * @return the locationPoint
     */
    public double[] getLocationPoint() {
        return locationPoint;
    }

    /**
     * @param locationPoint the locationPoint to set
     */
    public void setLocationPoint(double[] locationPoint) {
        this.locationPoint = locationPoint;
    }

    /**
     * @return the totDistance
     */
    public Double getTotDistance() {
        return totDistance;
    }

    /**
     * @param totDistance the totDistance to set
     */
    public void setTotDistance(Double totDistance) {
        this.totDistance = totDistance;
    }

    /**
     * @return the totTracks
     */
    public Integer getTotTracks() {
        return totTracks;
    }

    /**
     * @param totTracks the totTracks to set
     */
    public void setTotTracks(Integer totTracks) {
        this.totTracks = totTracks;
    }

    /**
     * @return the coordx
     */
    public Double getCoordx() {
        return coordx;
    }

    /**
     * @param coordx the coordx to set
     */
    public void setCoordx(Double coordx) {
        this.coordx = coordx;
    }

    /**
     * @return the coordy
     */
    public Double getCoordy() {
        return coordy;
    }

    /**
     * @param coordy the coordy to set
     */
    public void setCoordy(Double coordy) {
        this.coordy = coordy;
    }

    /**
     * @return the totTime
     */
    public long getTotTime() {
        return totTime;
    }

    /**
     * @param totTime the totTime to set
     */
    public void setTotTime(long totTime) {
        this.totTime = totTime;
    }

    /**
     * @return the totElevation
     */
    public Double getTotElevation() {
        return totElevation;
    }

    /**
     * @param totElevation the totElevation to set
     */
    public void setTotElevation(Double totElevation) {
        this.totElevation = totElevation;
    }

    /**
     * @return the totRealElevation
     */
    public Double getTotRealElevation() {
        return totRealElevation;
    }

    /**
     * @param totRealElevation the totRealElevation to set
     */
    public void setTotRealElevation(Double totRealElevation) {
        this.totRealElevation = totRealElevation;
    }

    /**
     * @return the dashboardPublic
     */
    public Boolean getDashboardPublic() {
        return dashboardPublic;
    }

    /**
     * @param dashboardPublic the dashboardPublic to set
     */
    public void setDashboardPublic(Boolean dashboardPublic) {
        this.dashboardPublic = dashboardPublic;
    }

    /**
     * @return the avatar
     */
    public CommonsMultipartFile getAvatar() {
        return avatar;
    }

    /**
     * @param avatar the avatar to set
     */
    public void setAvatar(CommonsMultipartFile avatar) {
        this.avatar = avatar;
    }

    /**
     * @return the tagsLink
     */
    public List<Tag> getTagsLink() {

        if (this.tagsLink == null || this.tagsLink.isEmpty()) {
            this.tagsLink = new ArrayList<Tag>();
        }
        return tagsLink;
    }

    /**
     * @param tagsLink the tagsLink to set
     */
    public void setTagsLink(List<Tag> tagsLink) {
        if (this.tagsLink == null || this.tagsLink.isEmpty()) {
            this.tagsLink = new ArrayList<Tag>();
        }
        this.tagsLink = tagsLink;
    }

    /**
     * @return the media
     */
    public List<Media> getMedia() {
        return media;
    }

    /**
     * @param media the media to set
     */
    public void setMedia(List<Media> media) {
        this.media = media;
    }

    /**
     *
     * @param media
     */
    public void addMedia(Media media) {

        if (this.media == null) {
            this.media = new ArrayList<Media>();
        }

        this.media.add(media);
    }
}
